<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>和为 K 的最少斐波那契数字数目</title>
</head>
<body>
  <script>
    function fn(k) {
      const f = [1];
      let a = 1, b = 1;
      while (a + b <= k) {
        let c = a + b;
        f.push(c);
        a = b;
        b = c;
      }
      let ans = 0;
      for (let i = f.length - 1; i >= 0 && k > 0; i--) {
        const num = f[i];
        if (k >= num) {
          k -= num
          ans++
        }
      }
      return ans
    }
    console.log(fn(7))
  </script>
</body>
</html>